package com.gitee.wsl.mathematics.algebraic.sample

import com.gitee.wsl.mathematics.algebraic.Ring
import com.gitee.wsl.mathematics.algebraic.number.NumericAlgebra
import com.gitee.wsl.mathematics.algebraic.op.Norm

interface Int16ExtendedField:Ring<Short>, Norm<Short, Short>, NumericAlgebra<Short>

/**
 * A field for [Short] without boxing. Does not produce an appropriate ring element.
 */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
 object Int16Ring : Int16ExtendedField {

    override val zero: Short get() = 0
    override val one: Short get() = 1

    override fun number(value: Number): Short = value.toShort()
    override fun add(left: Short, right: Short): Short = (left + right).toShort()
    override fun multiply(left: Short, right: Short): Short = (left * right).toShort()
    override fun norm(arg: Short): Short = if (arg > 0) arg else (-arg).toShort()

    override fun Short.unaryMinus(): Short = (-this).toShort()
    override fun Short.plus(arg: Short): Short = (this + arg).toShort()
    override fun Short.minus(arg: Short): Short = (this - arg).toShort()
    override fun Short.times(arg: Short): Short = (this * arg).toShort()
}
 typealias ShortRing = Int16Ring

 val Short.Companion.algebra: Int16Ring get() = Int16Ring